package com.example.shuiyin.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName("files")
public class FileInfo {
    @TableId(type = IdType.AUTO)
    private Long id;
    
    @TableField("file_id")
    private String fileId;
    
    @TableField("user_id")
    private Long userId;
    
    @TableField("filename")
    private String fileName;
    
    @TableField("original_name")
    private String originalName;
    
    @TableField("file_type")
    private String contentType;
    
    @TableField("size")
    private Long fileSize;
    
    @TableField("url")
    private String filePath;
    
    @TableField("thumbnail_url")
    private String thumbnailUrl;
    
    private String status;
    
    @TableField("file_hash")
    private String fileHash;
    
    @TableField("created_at")
    private LocalDateTime uploadTime;
    
    @TableField("last_access_time")
    private LocalDateTime lastAccessTime;
    
    @TableField("deleted_time")
    private LocalDateTime deletedTime;
    
    @TableField("updated_at")
    private LocalDateTime updatedAt;

    public String getUrl() {
        if (filePath == null || filePath.isEmpty()) {
            return null;
        }
        
        // 如果filePath已经是URL，则直接返回
        if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
            return filePath;
        }
        
        // 否则构建URL
        return "/api/file/" + fileId;
    }
}